package cn.tedu._03vehicle.base.intercepors;

import cn.tedu._03vehicle.pojo.vo.UserVO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("开始检验登录状态");
        HttpSession session=request.getSession();
        UserVO userVO = (UserVO)session.getAttribute("user");
        if(userVO==null){
            log.debug("用户未登录");
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
